package com.ungao.server;

import com.sun.net.httpserver.HttpServer;
import com.ungao.servlet.MiniHttpServlet;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.util.ServiceLoader;

public class MiniServer {

    protected static final String resourceLocation = "application.properties";

    public static void run() throws IOException {
        start();
    }

    public static void start() throws IOException {
        HttpServer httpServer = HttpServer.create(new InetSocketAddress(8080), 0);
        ServiceLoader<MiniHttpServlet> servlets = ServiceLoader.load(MiniHttpServlet.class);
        httpServer.createContext("/", servlets.iterator().next().config(resourceLocation));
        httpServer.start();
    }
}
